package algotithm.acwing.test826;


/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/7-16:56
 */
import java.util.*;

public class Main{

    private static int N = 100010;
    /**
     * value[] 数组存储的是当前节点的value值
     */
    private static int[] value = new int[N];
    /**
     * next[] 数组存储的是下一个结点的下标的值
     */
    private static int[] next = new int[N];

    /**
     * 头节点下标的位置
     */
    private static int head;

    /**
     * 下一个节点位置
     */
    private static int index;

    /**
     *初始化第1个插入节点下标为0，所以操作第k个数时都要-1 ！！
     */
    public static void init(){
        //头节点指向空
        head = -1;
        index = 0;
    }

    /**
     *插到头节点后
     */
    public static void insertH(int x){
        value[index] = x;
        next[index] = head;
        head = index;
        index++;
    }

    /**
     * 插到第k个节点后
     */
    public static void insertK(int k,int x){
        value[index] = x;
        next[index] = next[k];
        next[k] = index++;
    }

    /**
     * 删除第k个数后面的数
     */
    public static void delete(int k){
        next[k] = next[next[k]];
    }
    public static void main(String[] args){
        //别忘了先初始化！！！否则打印超时
        init();
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        while(m-- > 0){
            String op = scanner.next();
            if("H".equals(op)){
                int x =scanner.nextInt();
                insertH(x);
            }else if("D".equals(op)){
                int k =scanner.nextInt();
                if(k == 0){
                    //当k为0时，删除头结点，不是清空链表
                    head = next[head];
                }else{
                    delete(k - 1);
                }
            }else if("I".equals(op)){
                //k和x接收位置不要写反！！
                int k =scanner.nextInt();
                int x =scanner.nextInt();
                insertK(k - 1,x);
            }
        }

        for(int i = head;i != -1;i = next[i]){
            System.out.print(value[i] + " ");
        }
    }
}